<?php

namespace App\Eloquent;
use CancelPreAuthTrade;
use QueryHostingTrade;

class TradeRecords extends Model
{
  protected $fillable = [
    'type', 'project_id', 'sn', 'pay_user', 'receive_user','money','remarks','created_at','pay_time','end_time',
  	'card_number','status','gift','pid','user_balance','fee_money','user_fee'
  ];
  public $timestamps = false;
  /**
   * 查看类型
   * @return [type] [description]
   */
  public function assignType(){
    $arr=[1=>'分润',2=>'投资',3=>'还款',4=>'充值',5=>'提现',6=>'现金红包',7=>'投资红包',8=>'项目封包'];
    return $arr[$this->type];
  }
  /**
   * 投资撤销
   * @param  array  $sn_list    [description]
   * @param  string $remarks    [description]
   * @param  string $notify_url [description]
   * @return [type]          [description]
   */
  public static function cancelTrade($sn_list,$remarks,$notify_url=''){
  	$trade_list=array();
    $sn=createSn();
  	foreach ($sn_list as $value) {
  		$trade_list[]=$sn.'_fishing~'.$value.'~'.$remarks;
  	}
  	$data=[
  		'out_request_no'=>$sn,
  		'trade_list'=>implode('$',$trade_list),
  	];
    if(empty($data['notify_url'])){
      $data['notify_url']=config('sinapay.notify_url').'/return/cancelInvest';
    }
  	return CancelPreAuthTrade::send($data);
  }

  /**
   * 交易状态查询
   * @return [type] [description]
   */
  public function queryTrade(){
    $data=[
      'out_trade_no'=>$this->sn,
    ];
    return QueryHostingTrade::send($data);
  }
}